package com.example.qjia.model;

import android.os.Handler;
import android.util.Log;

import com.example.qjia.Listener.ModifyMessageListener;
import com.example.qjia.data.romotedata.ResponseData;
import com.example.qjia.util.retrofit.RetrofitNet;

import java.util.Map;

import rx.Observer;

/**
 * Created by ying_xiang on 2016/8/29.
 */
public class ModifyMessageModelImp implements ModifyMesageModel {


    @Override
    public void modifyStudentMailorPhone(final Map<String,String>params, final ModifyMessageListener listener) {
        System.out.println("执行修改模型");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                new RetrofitNet().updateStudentInfo(params,new Observer<ResponseData>() {
                    @Override
                    public void onCompleted() {
                        //完成
                        System.out.println("finish");
                    }

                    @Override
                    public void onError(Throwable e) {
                        //异常
                        System.out.println("error");
                        Log.e("MAIN2",e.getLocalizedMessage()+"--"+e.getMessage());
                    }

                    @Override
                    public void onNext(ResponseData baseBean) {
                        //成功
                        ResponseData  p=baseBean;
                        System.out.println("有返回:");
                        System.out.println("p.getCode()="+p.getCode()+",    p.getMsg()="+p.getMsg());
                        if(p.getCode()==0) {            //表示提交成功


                            System.out.println(p.getCode() + "--" + p.getMsg());
                            listener.modifySuccess();
                        }else{
                            listener.modifyFailed();
                        }

                    }
                });




            }
        }, 1000);
    }


    @Override
    public void modifyStudentPassword(Map<String, String> passwordParams, ModifyMessageListener listener) {

    }
}
